/*
 * @Author: gonglf
 * @Date: 2022-08-11 15:27:36
 * @LastEditors: gonglf
 * @LastEditTime: 2022-08-11 20:35:38
 * @Description:
 *
 */
package main

import (
	"fmt"
	"io"
	"net/http"
	"time"
)

func main() {
	//resp, _ := http.Get("http://www.baidu.com")
	//fmt.Println(resp)
	resp, _ := http.Get("http://127.0.0.1:8000/go")
	defer resp.Body.Close()
	// 200 OK
	fmt.Println(resp.Status)
	fmt.Println(resp.Header)

	for {
		// 接收服务端信息
		buf := make([]byte, 1024)
		n, err := resp.Body.Read(buf)
		if err != nil && err != io.EOF {
			fmt.Println(err)
			return
		} else {
			fmt.Println("读取完毕")
			res := string(buf[:n])
			fmt.Println(res, n, err)
			// break
		}
		time.Sleep(1 * time.Second)
	}
}
